﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Configuration;

namespace HoneyBadgersOfficePlayer.Models
{
    public partial class FTPUtilities
    {
        public static void Upload(string filename)
        {
            if (Convert.ToBoolean(ConfigurationManager.AppSettings.Get("EnableFTP")))
            {
                string uploadFileName = ConfigurationManager.AppSettings.Get("FTPDirectory") + "/" + Globals.UserID + "/" + filename;
                FtpWebRequest reqFTP;
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uploadFileName));
                reqFTP.Credentials = new NetworkCredential(ConfigurationManager.AppSettings.Get("FTPLogin"), ConfigurationManager.AppSettings.Get("FTPPassword"));
                reqFTP.KeepAlive = false;
                reqFTP.UsePassive = true;
                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

                using (System.IO.Stream reqStream = reqFTP.GetRequestStream())
                {
                    byte[] data = File.ReadAllBytes(filename);
                    reqStream.Write(data, 0, data.Length);
                }
            }
        }
    }
}
